home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / CRS / crs53.d81 / 28may87s.pma / CXVT.ASM < prev    next >
Assembly Source File  |  1979-12-31  |  19KB  |  1,035 lines

  1.  
  2.  
  3.  
  4.     title    'Terminal Emulation (VT-100)   18 Feb 86'
  5.  
  6.     maclib    cxequ
  7.  
  8.     if  use$VT100
  9.  
  10.     maclib    z80
  11.  
  12. lines    equ    24
  13.  
  14.     public    VT100
  15.  
  16. ;
  17. ;    VT-100
  18. ;
  19. ;    NUL        00h    ignored
  20. ;    ENQ        05h    transmit answer back message
  21. ;    BEL        07h    ring bell
  22. ;    BS        08h    back space. stop at left margin
  23. ;    HT        09h    do TAB
  24. ;    LF        0Ah    do line feed scroll at bottom
  25. ;    VT        0Bh    same as LF
  26. ;    FF        0Ch    same as LF
  27. ;    CR        0Dh    do CR
  28. ;    SO        0Eh    invoke G1 set
  29. ;    SI        0Fh    invoke G0 set
  30. ;    XON        11h    ignored
  31. ;    XOFF        13h    ignored
  32. ;    CAN        18h    abort ESC seq (disp error character)
  33. ;    SUB        1Ah    same as CAN
  34. ;    ESC        1Bh    control seq
  35. ;    DEL        7Fh    not used
  36. ;
  37. ;    ESC =            Keypad mode
  38. ;    ESC >            Keypad mode
  39. ;    ESC 7            Save current cursor post and char set
  40. ;    ESC 8            Restore cursor position and char set
  41. ;    ESC D            move cursor down one line
  42. ;    ESC E            move cursor to start of next line
  43. ;    ESC H            set horizontal tab
  44. ;    ESC M            move cursor up one line
  45. ;    ESC Z            same as ESC [ Pn c
  46. ;    ESC c            reset
  47. ;    ESC # 3            Double height line Top
  48. ;    ESC # 4            Double height line Bottom
  49. ;    ESC # 5            set single width line
  50. ;    ESC # 6            Double width line
  51. ;    ESC # 8            files screen with E's
  52. ;    ESC [ Pn A        cursor up
  53. ;    ESC [ Pn B        cursor down
  54. ;    ESC [ Pn C        cursor right
  55. ;    ESC [ Pn D        cursor left
  56. ;    ESC [ Pn ; Pn H        cursor positioning
  57. ;    ESC [ Ps J        erase display
  58. ;    ESC [ Ps K        erase line
  59. ;    ESC [ Pn c        device attributes request
  60. ;    ESC [ Pn ; Pn f        cursor positioning
  61. ;    ESC [ Ps g        clear tab stop(s)
  62. ;    ESC [ Ps;..;Ps h    set mode
  63. ;    ESC [ Ps;..;Ps l    reset attributes
  64. ;    ESC [ Ps;..;Ps m    set attributes
  65. ;    ESC [ Ps n        Device status report
  66. ;    ESC [ Ps q        set LED's
  67. ;    ESC [ Pn ; Pn r        Set Top and Bottom Margins
  68. ;    ESC [ 2 ; Ps y        invoke confidence test
  69. ;    ESC [ x            Report / Req parameters
  70. ;;    ESC ( A            select char set
  71. ;;    ESC ( B            select char set
  72. ;;    ESC ( 0            select char set
  73. ;;    ESC ( 1            select char set
  74. ;;    ESC ( 2            select char set
  75. ;;    ESC ) A            select char set
  76. ;;    ESC ) B            select char set
  77. ;;    ESC ) 0            select char set
  78. ;;    ESC ) 1            select char set
  79. ;;    ESC ) 2            select char set
  80. ;
  81.     page
  82.  
  83.     dseg
  84. ;
  85. ;    VT-100 terminal emulation
  86. ;
  87. VT100:
  88.     lhld    parm$base        ; 1st parm is exec adr (2 bytes)
  89.     mov    a,m
  90.     inx    h
  91.     mov    h,m
  92.     mov    l,a
  93.     ora    h            ; L is in A already, test HL=0
  94.     mov    a,c            ; C is char to output
  95.     jrz    start$checking 
  96.     pchl
  97. ;
  98. ;
  99. ;
  100. start$checking:
  101.     lxi    h,control$table
  102.     lxi    b,cnt$tbl$lng
  103.     ccir
  104.     lxi    h,control$exec$adr
  105.     jrz    find$exec$adr
  106.     cpi    20h
  107.     rc
  108.  
  109. do$direct:
  110.     mov    d,a
  111.     TJMP    FR$wr$char
  112.  
  113.     page
  114. ;
  115. ;
  116. ;
  117. do$ESC:        ; ESC    control seq
  118.     call    cont$later
  119. ;
  120. ;    ESC char    look for char in the ESC table
  121. ;
  122.     call    remove$exec$adr
  123.     lxi    h,esc$table
  124.     lxi    b,esc$tbl$lng
  125.     ccir
  126.     rnz                ; bad esc sequence
  127.     lxi    h,esc$exec$adr
  128.  
  129. find$exec$adr:
  130.     dad    b
  131.     dad    b
  132.     mov    a,m
  133.     inx    h
  134.     mov    h,m
  135.     mov    l,a
  136.     pchl
  137.  
  138.     page
  139. ;
  140. ;    ESC #
  141. ;
  142. esc$pn:        ; ESC # control seq
  143.     call    cont$later
  144. ;
  145. ;    ESC # char    look for char in the ESC table
  146. ;
  147.     call    remove$exec$adr
  148.     lxi    h,esc$pnd$table
  149.     lxi    b,esc$pnd$tbl$lng
  150.     ccir
  151.     rnz                ; bad esc sequence
  152.     lxi    h,esc$pnd$exec$adr
  153.     jr    find$exec$adr
  154.  
  155.     page
  156. ;
  157. ;    ESC [
  158. ;
  159. esc$br:        ; ESC [
  160.     call    clear$parm
  161.     call    cont$later
  162. ;
  163. ;    ESC [ char    look for char in the ESC table
  164. ;
  165.     cpi    '9'+1            ; input char a parameter
  166.     jrc    put$buffer        ; yes, save parameters in buffer
  167.     call    remove$exec$adr
  168.     lxi    h,esc$br$table
  169.     lxi    b,esc$br$tbl$lng
  170.     ccir
  171.     rnz                ; bad esc sequence
  172.     lxi    h,esc$br$exec$adr
  173.     jr    find$exec$adr
  174. ;
  175. ;    put byte in buffer pointed to by the put pointer+1 (advance pointer)
  176. ;
  177. put$buffer:
  178.     mov    c,a            ; save character in C
  179.     call    get$par            ; get address of parameter buffer
  180.     mov    e,m            ; get low byte adr of input buffer
  181.     inx    h
  182.     mov    d,m            ; get high byte adr of input buffer
  183.     inx    h
  184.     inr    m            ; advance input count
  185.     mov    l,m            ; get current count (with input)
  186.     mvi    h,0            ;
  187.     dad    d            ; compute adr in buf to place input
  188.     mov    m,c            ; place input character into buffer
  189. ;    stc
  190.     ret
  191. ;
  192. ;    get byte from buffer pointed to by the get pointer+1 (advance pointer)
  193. ;
  194. get$buffer:
  195.     call    get$par
  196.     mov    e,m
  197.     inx    h
  198.     mov    d,m
  199.     inx    h
  200.     mov    a,m        ; recover put counter
  201.     inx    h
  202.     sub    m        ; test for end
  203.     rz
  204.     inr    m        ; advance get counter
  205.     mov    l,m        ; get the get counter
  206.     mvi    h,0
  207.     dad    d
  208.     mov    a,m
  209. do$DEL:        ; DEL    not used
  210.     ret
  211.  
  212.     page
  213. ;
  214. ;
  215. ;
  216. do$CAN:        ; CAN SUB  abort ESC seq (disp error character)
  217.  
  218. ;
  219. ;    Invoke G0 char set
  220. ;
  221. do$SI:        ; SI    invoke G0 set
  222.     ret
  223.  
  224. ;
  225. ;    Invoke G1 char set
  226. ;
  227. do$SO:        ; SO    invoke G1 set
  228.     ret
  229.  
  230. ;
  231. ;    move cursor to margin on current line
  232. ;
  233. do$CR:        ; CR    do CR
  234.     TJMP    FR$do$cr
  235.  
  236. ;
  237. ;    
  238. ;
  239. do$LF:        ; FF VT LF    do line feed scroll at bottom
  240.     TJMP    FR$cursor$down
  241.  
  242. ;
  243. ;    move cursor to next tab stop or right margin if none
  244. ;
  245. do$HT:        ; HT    do TAB
  246.     ret
  247.  
  248. ;
  249. ;    move cursor to left but not past left margin
  250. ;
  251. do$BS:        ; BS    back space. stop at left margin
  252.     TJMP    FR$cursor$left
  253.  
  254. ;
  255. ;    Sound bell tone
  256. ;
  257. do$BEL:        ; BEL    ring bell
  258.     RJMP    FR$bell
  259.  
  260. ;
  261. ;    transmit answerback message
  262. ;
  263. do$ENQ:        ; ENQ    transmit answer back message
  264.     ret
  265.  
  266. ;
  267. ;
  268. ;
  269. esc$pn$8:    ; ESC # 8    files screen with E's
  270.     lxi    d,024*256+0    ; set row (D) and col (E)
  271.     mvi    c,24        ; set # of rows (C)
  272. out$next$line$E:
  273.     mvi    b,80        ; set # of col (B)
  274.     dcr    d        ; start with row 0
  275.     push    d
  276.     push    b
  277.     TCALL    FR$cursor$pos
  278.     pop    b
  279. out$next$E:
  280.     push    b
  281.     mvi    d,'E'
  282.     TCALL    FR$wr$char
  283.     pop    b
  284.     djnz    out$next$E
  285.     pop    d
  286.     dcr    c
  287.     jrnz    out$next$line$E
  288.     ret
  289.  
  290. ;
  291. ;
  292. ;
  293. esc$pn$6:    ; ESC # 6    Double width line
  294.     ret
  295.  
  296. ;
  297. ;
  298. ;
  299. esc$pn$5:    ; ESC # 5    set single width line
  300.     ret
  301.  
  302. ;
  303. ;
  304. ;
  305. esc$pn$4:    ; ESC # 4    Double height line Bottom
  306.     ret
  307.  
  308. ;
  309. ;
  310. ;
  311. esc$pn$3:    ; ESC # 3    Double height line Top
  312.     ret
  313.  
  314. ;
  315. ;    Set tab at current cursor column
  316. ;
  317. esc$HH:        ; ESC H    set horizontal tab
  318.     ret
  319.  
  320. ;
  321. ;    Move cursor down one line, scroll if on bottom margin
  322. ;
  323. esc$DD:        ; ESC D    move cursor down one line
  324.  
  325.     ret
  326.  
  327. ;
  328. ;    Move cursor to start of next line, scroll up if cursor
  329. ;    is on the bottom margin
  330. ;
  331. esc$EE:        ; ESC E    move cursor to start of next line
  332.     
  333.     ret
  334.  
  335. ;
  336. ;    Move cursor up one line, if on top margin scroll down
  337. ;
  338. esc$MM:        ; ESC M    move cursor up one line
  339.  
  340.     ret
  341.  
  342. ;
  343. ;    reset VT100 to initial state (causes INIT H to be asserted
  344. ;    briefly ???)
  345. ;
  346. esc$c:        ; ESC c    reset
  347.     ret
  348.  
  349. ;
  350. ;
  351. ;
  352. esc$8:        ; ESC 8    Restore cursor position and char set
  353.     ret
  354.  
  355. ;
  356. ;
  357. ;
  358. esc$7:        ; ESC 7    Save current cursor post and char set
  359.     ret
  360.  
  361. ;
  362. ;    place Keypad into Numeric mode
  363. ;
  364. esc$gt:        ; ESC >    Keypad mode
  365.     ret
  366.  
  367. ;
  368. ;    place Keypad into Application mode
  369. ;
  370. esc$equ:    ; ESC =    Keypad mode
  371.     ret
  372.  
  373. ;
  374. ;
  375. ;
  376. esc$br$y:    ; ESC [2;Ps y    invoke confidence test
  377.     ret
  378.  
  379. ;
  380. ;
  381. ;
  382. esc$br$x:    ; ESC [ x    Report / Req parameters
  383.     ret
  384.  
  385. ;
  386. ;
  387. ;
  388. esc$br$r:    ; ESC [Pn;Pn r    Set Top and Bottom Margins
  389.     ret
  390.  
  391. ;
  392. ;    Ps=0    clear all LED's (default)
  393. ;    PS=1    set LED 1
  394. ;    Ps=2    set LED 2
  395. ;    Ps=3    set LED 3
  396. ;    Ps=4    set LED 4
  397. ;
  398. esc$br$q:    ; ESC [Ps q    set LED's
  399.     ret
  400.  
  401. ;
  402. ;    Ps=5    Status Report
  403. ;        responce is:    ESC [0n (terminal OK)
  404. ;                ESC [3n (terminal not OK)
  405. ;    Ps=6    Report cursor position
  406. ;        responce is:    ESC [ Pl ; Pc R
  407. ;        where Pl is the line number
  408. ;        and Pc is column number
  409. ;
  410. esc$br$n:    ; ESC [Ps n    Device status report
  411.     ret
  412.  
  413. ;
  414. ;    Ps=0    attributes off (default)
  415. ;    Ps=1    bold or increased intensity
  416. ;    Ps=4    underscore
  417. ;    Ps=5    blink
  418. ;    Ps=7    reverse video
  419. ;
  420. esc$br$m:    ; ESC [Ps;;Ps m set character attributes
  421.     call    get$Pn$def0$init
  422. check$br$m:
  423.     dcr    c        ; check # of parameters used
  424.     rz            ; exit if None
  425.     ana    a        ; Ps=0 ?
  426.     jrz    set$atr$off    ; set attributes off
  427.     dcr    a        ; Ps=1
  428.     jrz    bold$on        ;
  429.     dcr    a        ; Ps=2
  430.     dcr    a        ; Ps=3
  431.     dcr    a        ; Ps=4
  432.     jrz    underline$on    ;
  433.     dcr    a        ; Ps=5
  434.     jrz    blink$on    ;
  435.     dcr    a        ; Ps=6
  436.     dcr    a        ; Ps=7
  437.     jrz    reverse$on    ;
  438.     call    get$Pn$def0
  439.     jr    check$br$m
  440.  
  441. set$atr$off:
  442. bold$on:
  443. underline$on:
  444. blink$on:
  445. reverse$on:
  446.     ret
  447.  
  448.  
  449. ;
  450. ;    Ps=1    cursor key    (l=cursor ; h=application)
  451. ;    Ps=2    ANSI/VT52    (l=VT52  not supported)
  452. ;    Ps=3    Column        (l=80 col ; h=132 col) 80 only
  453. ;    Ps=4    Scrolling    (l=jump ; h=smooth) smooth only
  454. ;    Ps=5    Screen        (l=normal ; h=reverse)
  455. ;    Ps=6    Origin        (l=Absolute ; h=Relative)
  456. ;    Ps=7    Auto wrap    (l=off ; h=on)
  457. ;    Ps=8    Auto Repeat    (l=off ; h=on)
  458. ;    Ps=9    interlace    (l=off ; h=on)
  459. ;    Ps=20    LF/NL        (l=line feed ; h=new line)
  460. ;
  461. esc$br$l:    ; ESC [Ps;;Ps l    reset mode
  462.     ret
  463. ;
  464. ;    see esc$br$l 
  465. ;
  466. esc$br$h:    ; ESC [Ps;;Ps h    set mode
  467.     ret
  468.  
  469. ;
  470. ;    Ps=0    clear tab stop at current column (default)
  471. ;    Ps=3    clear ALL tab stops
  472. ;
  473. esc$br$g:    ; ESC [Ps g    clear tab stop(s)
  474.     ret
  475.  
  476. ;
  477. ;    Pn default =1    missing Pn uses default value(s)
  478. ;    position cursor to line (1st) and column (2nd)
  479. ;    uses DECOM parm to set origin mode (within margin
  480. ;    or full screen)
  481. ;
  482. esc$br$f:    ; ESC [Pn;Pn f    cursor positioning
  483. esc$br$HH:    ; ESC [Pn;Pn H    cursor positioning
  484.     call    get$Pn$def1$init
  485.     dcr    a
  486.     mov    d,a
  487.     call    get$Pn$def1        ; DE are not changed by this call
  488.     dcr    a
  489.     mov    e,a
  490.     TJMP    FR$cursor$pos
  491.  
  492. ;
  493. ;    What are you
  494. ;    response is:    ESC [?1; Ps c
  495. ;    where Ps is:
  496. ;        0=base VT100, no options
  497. ;        1=processor option (STP)
  498. ;        2=advanced video option (AVO)
  499. ;        3=AVO and STP
  500. ;        4=graphics processor option (GPO)
  501. ;        5=GPO and STP
  502. ;        6=GPO and AVO
  503. ;        7=GPO, STP and AVO
  504. ;
  505. esc$ZZ:        ; ESC Z        same as ESC [ Pn c
  506. esc$br$c:    ; ESC [Pn c    device attributes request
  507.     ret
  508.  
  509. ;
  510. ;    Ps=0    from cursor to end of line (default)
  511. ;    Ps=1    from start of line to cursor
  512. ;    Ps=2    all of cursor line
  513. ;
  514. esc$br$KK:    ; ESC [Ps K    erase line
  515.     ret
  516.  
  517. ;
  518. ;    Ps=0    from cursor to end of screen
  519. ;    Ps=1    from start of screen to cursor
  520. ;    Ps=2    all of screen (cursor is not moved)
  521. ;
  522. esc$br$JJ:    ; ESC [Ps J    erase display
  523.     ret
  524.  
  525. ;
  526. ;
  527. ;
  528. esc$br$DD:    ; ESC [Pn D    cursor left
  529.     ret
  530.  
  531. ;
  532. ;
  533. ;
  534. esc$br$CC:    ; ESC [Pn C    cursor right
  535.     ret
  536.  
  537. ;
  538. ;
  539. ;
  540. esc$br$BB:    ; ESC [Pn B    cursor down
  541.     ret
  542.  
  543. ;
  544. ;
  545. ;
  546. esc$br$AA:    ; ESC [Pn A    cursor up
  547.     ret
  548.  
  549.     page
  550. ;
  551. ;    convert number to binary
  552. ;    stop conversion at end or any none number
  553. ;    (DE may not be changed)
  554. ;
  555. get$Pn$def0$init:
  556.     call    init$get        ; set up to read buffer
  557. ;
  558. get$Pn$def0:
  559.     call    get$in$parm
  560.     mov    a,b            ; get input data to A
  561.     ret
  562. ;
  563. ;*****    NOTE    ESC [ ;4;A    is the same as ESC [ 0;4;5A
  564. ;
  565. ;
  566. ;    convert number to binary
  567. ;    stop conversion at end or any none number
  568. ;    return 1 if input is missing or a zero
  569. ;    (DE may not changed)
  570. ;
  571. get$Pn$def1$init:
  572.     call    init$get        ; set up to read buffer
  573. ;
  574. get$Pn$def1:
  575.     call    get$in$parm
  576.     mov    a,b            ; get input data to A
  577.     ora    a            ; is input =0?
  578.     rnz                ; no, then use it
  579.     inr    a            ; yes, then use default of 1
  580.     ret
  581.  
  582. ;
  583. ;    B=converted number in binary (from input string)
  584. ;    C=number of digits converted+1
  585. ;    A=0 if ran out of input else A=last character read from string
  586. ;    (DE may not be changed)
  587. ;
  588. get$in$parm:
  589.     lxi    b,1            ; B=0, C=1
  590. get$next$num:
  591.     lda    save$count
  592.     dcr    a
  593.     rz
  594.     sta    save$count
  595.     lhld    buff$pointer        ; get input buffer adr
  596.     inx    h            ; PRE incr adr
  597.     shld    buff$pointer
  598.     mov    a,m
  599.     call    test$num
  600.     rc
  601.     slar    b            ; 2x
  602.     add    b            ; A=A+2B
  603.     slar    b            ; 4x
  604.     slar    b            ; 8x
  605.     add    b            ; A=A+2B+8B=A+10B
  606.     mov    b,a            ; save in B
  607.     inr    c            ; advance parmeter count
  608.     jr    get$next$num
  609.  
  610. ;
  611. ;    return with carry set (Cy=1) if not a number (A=input Char)
  612. ;    return bianary number in A if it was a number (Cy=0)
  613. ;
  614. test$num:
  615.     cpi    '0'
  616.     rc
  617.     cpi    '9'+1
  618.     cmc
  619.     rc
  620.     sui    '0'
  621.     ret
  622. ;
  623. ;    set up local values to use buffer parameters
  624. ;
  625. init$get:
  626.     call    get$par            ; get pointer to buffer(s)
  627.     mov    e,m
  628.     inx    h
  629.     mov    d,m
  630.     inx    h
  631.     mov    a,m
  632.     inr    a            ; adjust for PRE decr
  633.     sta    save$count
  634. ;    inx    h
  635. ;    mov    a,m
  636. ;    sta    get$count
  637.     xchg
  638.     shld    buff$pointer
  639.     ret
  640.  
  641. save$count:
  642.     db    0
  643. buff$pointer:
  644.     dw    0
  645.  
  646.     page
  647. ;
  648. ;    set buffer back to start
  649. ;
  650. clear$parm:
  651.     call    get$par
  652.     inx    h
  653.     inx    h
  654.     mvi    m,0        ; zero out the input count
  655.     ret
  656. ;
  657. ;
  658. ;
  659. get$par:
  660.     lxi    h,vt100$par$80
  661.     lda    fun$offset
  662.     ana    a
  663.     rz
  664.     lxi    h,vt100$par$40
  665.     ret
  666. ;
  667. ;
  668. ;
  669. vt100$par$80:
  670.     dw    buffer$80
  671.     db    0        ; current put pointer into buffer
  672. ;
  673. ;
  674. ;
  675. vt100$par$40:
  676.     dw    buffer$40
  677.     db    0        ; current put pointer into buffer
  678.  
  679. buffer$80    equ    $-1
  680.     ds    20
  681. buffer$40    equ    $-1
  682.     ds    20
  683.  
  684.     page
  685. ;
  686. ;
  687. ;
  688. cont$later:
  689.     pop    h        ; get address to cont at in H
  690.     jr    save$exec$adr    ; save it
  691. ;
  692. ;
  693. ;
  694. remove$exec$adr:
  695.     lxi    h,0
  696. save$exec$adr:
  697.     xchg
  698.     lhld    parm$base
  699.     mov    m,e
  700.     inx    h
  701.     mov    m,d
  702.     ret
  703.  
  704.     page
  705. ;
  706. ;    table scanned top to bottom
  707. ;
  708. control$table:
  709.     db    05h    ; ENQ    transmit answer back message
  710.     db    07h    ; BEL    ring bell
  711.     db    08h    ; BS    back space. stop at left margin
  712.     db    09h    ; HT    do TAB
  713.     db    0Ah    ; LF    do line feed scroll at bottom
  714.     db    0Bh    ; VT    same as LF
  715.     db    0Ch    ; FF    same as LF
  716.     db    0Dh    ; CR    do CR
  717.     db    0Eh    ; SO    invoke G1 set
  718.     db    0Fh    ; SI    invoke G0 set
  719.     db    18h    ; CAN    abort ESC seq (disp error character)
  720.     db    1Ah    ; SUB    same as CAN
  721.     db    1Bh    ; ESC    control seq
  722.     db    7Fh    ; DEL    not used
  723.  
  724. cnt$tbl$lng    equ    $-control$table
  725.  
  726. ;
  727. ;    table scanned bottom to top
  728. ;
  729. control$exec$adr:
  730.     dw    do$DEL        ; DEL    not used
  731.     dw    do$ESC        ; ESC    control seq
  732.     dw    do$CAN        ; SUB    same as CAN
  733.     dw    do$CAN        ; CAN    abort ESC seq (disp error character)
  734.     dw    do$SI        ; SI    invoke G0 set
  735.     dw    do$SO        ; SO    invoke G1 set
  736.     dw    do$CR        ; CR    do CR
  737.     dw    do$LF        ; FF    same as LF
  738.     dw    do$LF        ; VT    same as LF
  739.     dw    do$LF        ; LF    do line feed scroll at bottom
  740.     dw    do$HT        ; HT    do TAB
  741.     dw    do$BS        ; BS    back space. stop at left margin
  742.     dw    do$BEL        ; BEL    ring bell
  743.     dw    do$ENQ        ; ENQ    transmit answer back message
  744.  
  745.     page
  746. ;
  747. ;    table scanned top to bottom
  748. ;
  749. esc$table:
  750.     db    '='        ; ESC =    Keypad mode
  751.     db    '>'        ; ESC >    Keypad mode
  752.     db    '7'        ; ESC 7    Save current cursor post and char set
  753.     db    '8'        ; ESC 8    Restore cursor position and char set
  754.     db    'D'        ; ESC D    move cursor down one line
  755.     db    'E'        ; ESC E    move cursor to start of next line
  756.     db    'H'        ; ESC H    set horizontal tab
  757.     db    'M'        ; ESC M    move cursor up one line
  758.     db    'Z'        ; ESC Z    same as ESC [ Pn c
  759.     db    'c'        ; ESC c    reset
  760.     db    '#'        ; ESC # control seq
  761.     db    '['        ; ESC [ cursor up
  762. esc$tbl$lng    equ    $-esc$table
  763.  
  764. ;
  765. ;    table scanned bottom to top
  766. ;
  767. esc$exec$adr:
  768.     dw    esc$br        ; ESC [ cursor up
  769.     dw    esc$pn        ; ESC # control seq
  770.     dw    esc$c        ; ESC c reset
  771.     dw    esc$ZZ        ; ESC Z    same as ESC [ Pn c
  772.     dw    esc$MM        ; ESC M move cursor up one line
  773.     dw    esc$HH        ; ESC H    set horizontal tab
  774.     dw    esc$EE        ; ESC E move cursor to start of next line
  775.     dw    esc$DD        ; ESC D move cursor down one line
  776.     dw    esc$8        ; ESC 8    Restore cursor position and char set
  777.     dw    esc$7        ; ESC 7    Save current cursor post and char set
  778.     dw    esc$gt        ; ESC >    Keypad mode
  779.     dw    esc$equ        ; ESC =    Keypad mode
  780.  
  781. ;
  782. ;
  783. ;
  784. esc$pnd$table:
  785.     db    '3'    ; ESC # 3    Double height line Top
  786.     db    '4'    ; ESC # 4    Double height line Bottom
  787.     db    '5'    ; ESC # 5    set single width line
  788.     db    '6'    ; ESC # 6    Double width line
  789.     db    '8'    ; ESC # 8    files screen with E's
  790.  
  791. esc$pnd$tbl$lng    equ    $-esc$pnd$table
  792.  
  793. esc$pnd$exec$adr:
  794.     dw    esc$pn$8    ; ESC # 8    files screen with E's
  795.     dw    esc$pn$6    ; ESC # 6    Double width line
  796.     dw    esc$pn$5    ; ESC # 5    set single width line
  797.     dw    esc$pn$4    ; ESC # 4    Double height line Bottom
  798.     dw    esc$pn$3    ; ESC # 3    Double height line Top
  799.  
  800. ;
  801. ;
  802. ;
  803. esc$br$table:
  804.     db    'A'    ; ESC [ Pn A        cursor up
  805.     db    'B'    ; ESC [ Pn B        cursor down
  806.     db    'C'    ; ESC [ Pn C        cursor right
  807.     db    'D'    ; ESC [ Pn D        cursor left
  808.     db    'H'    ; ESC [ Pn ; Pn H    cursor positioning
  809.     db    'J'    ; ESC [ Ps J        erase display
  810.     db    'K'    ; ESC [ Ps K        erase line
  811.     db    'c'    ; ESC [ Pn c        device attributes request
  812.     db    'f'    ; ESC [ Pn ; Pn f    cursor positioning
  813.     db    'g'    ; ESC [ Ps g        clear tab stop(s)
  814.     db    'h'    ; ESC [ Ps;..;Ps h    set mode
  815.     db    'l'    ; ESC [ Ps;..;Ps l    reset attributes
  816.     db    'm'    ; ESC [ Ps;..;Ps m    set attributes
  817.     db    'n'    ; ESC [ Ps n        Device status report
  818.     db    'q'    ; ESC [ Ps q        set LED's
  819.     db    'r'    ; ESC [ Pn ; Pn r    Set Top and Bottom Margins
  820.     db    'x'    ; ESC [ x        Report / Req parameters
  821.     db    'y'    ; ESC [ 2 ; Ps y    invoke confidence test
  822.  
  823. esc$br$tbl$lng    equ    $-esc$br$table
  824.  
  825. esc$br$exec$adr:
  826.     dw    esc$br$y    ; ESC [2;Ps y    invoke confidence test
  827.     dw    esc$br$x    ; ESC [ x    Report / Req parameters
  828.     dw    esc$br$r    ; ESC [Pn;Pn r    Set Top and Bottom Margins
  829.     dw    esc$br$q    ; ESC [Ps q    set LED's
  830.     dw    esc$br$n    ; ESC [Ps n    Device status report
  831.     dw    esc$br$m    ; ESC [Ps;;Ps m set attributes
  832.     dw    esc$br$l    ; ESC [Ps;;Ps l    reset attributes
  833.     dw    esc$br$h    ; ESC [Ps;;Ps h    set mode
  834.     dw    esc$br$g    ; ESC [Ps g    clear tab stop(s)
  835.     dw    esc$br$f    ; ESC [Pn;Pn f    cursor positioning
  836.     dw    esc$br$c    ; ESC [Pn c    device attributes request
  837.     dw    esc$br$KK    ; ESC [Ps K    erase line
  838.     dw    esc$br$JJ    ; ESC [Ps J    erase display
  839.     dw    esc$br$HH    ; ESC [Pn;Pn H    cursor positioning
  840.     dw    esc$br$DD    ; ESC [Pn D    cursor left
  841.     dw    esc$br$CC    ; ESC [Pn C    cursor right
  842.     dw    esc$br$BB    ; ESC [Pn B    cursor down
  843.     dw    esc$br$AA    ; ESC [Pn A    cursor up
  844.  
  845.     endif
  846.     end
  847.  
  848. ;
  849. ;
  850. ;
  851. esc$esc:
  852.     call    cont$later
  853. ;
  854. ;    check for ESC ESC ESC
  855. ;
  856.     cpi    esc            ; check if 3rd char is an ESC
  857.     jrnz    remove$exec$adr
  858.     call    cont$later
  859. ;
  860. ;    set current character as the attr
  861. ;
  862.     mov    b,a
  863.     TCALL    FR$color
  864.     jr    remove$exec$adr
  865.  
  866.  
  867. ;
  868. ;
  869. ;
  870. esc$equ:
  871.     call    cont$later
  872. ;
  873. ;    ESC = R
  874. ;
  875.     lhld    parm$base
  876.     inx    h
  877.     inx    h
  878.     sui    ' '            ; remove ascii bias
  879.     mov    m,a
  880.     cpi    '8'-' '            ; test for line 25 (A=24?)
  881.     jrnz    not$status$line        ; no, jmp
  882.     inr    a            ; yes, A=25
  883.     sta    paint$size        ; set 40 column repaint to 25 lines
  884. not$status$line:
  885.     call    cont$later
  886. ;
  887. ;    ESC = R C    (go do it)
  888. ;
  889.     sui    ' '
  890.     mov    e,a            ; column # to E
  891.  
  892.     lhld    parm$base
  893.     inx    h
  894.     inx    h
  895.     mov    d,m            ; row # to D
  896.     TCALL    FR$cursor$pos
  897.     jr    remove$exec$adr
  898.  
  899.     page
  900. ;
  901. ;
  902. ;
  903. char$cnt$z:                ; ^Z    home and clear screen
  904.     lxi    d,lines*256+0        ; B=24(row) C=0(col)
  905.     TCALL    FR$cursor$pos
  906.     call    esc$t            ; clear the status line 
  907.     lxi    d,0
  908.     TCALL    FR$cursor$pos
  909. esc$y:
  910.     TJMP    FR$CES            ; clear to end of screen 
  911.  
  912. home$cursor:
  913.     lxi    d,0
  914.     TJMP    FR$cursor$pos
  915.     
  916. esc$t:
  917.     TJMP    FR$CEL            ; clear to end of line 
  918.  
  919. ;
  920. ;
  921. ;
  922. cursor$rt:
  923.     TJMP    FR$cursor$rt
  924.  
  925. ;
  926. ;
  927. ;
  928. cursor$up:
  929.     TJMP    FR$cursor$up
  930.  
  931.  
  932.     page
  933.  
  934. ;
  935. ;    delete character
  936. ;
  937. esc$W:
  938.     TJMP    FR$char$del
  939.  
  940. ;
  941. ;    delete line
  942. ;
  943. esc$R:
  944.     TJMP    FR$line$del
  945.  
  946. ;
  947. ;    insert character
  948. ;
  949. esc$Q:
  950.     TJMP    FR$char$ins
  951.  
  952. ;
  953. ;    insert line
  954. ;
  955. esc$E:
  956.     TJMP    FR$line$ins
  957.  
  958.     page
  959. ;
  960. ;    Half Intensity Off
  961. ;
  962. esc$lfp:
  963.     mvi    c,00000001b        ; turn intensity up
  964.     jr    set$FR$atr$c
  965. ;
  966. ;    Half Intensity On
  967. ;
  968. esc$rtp:
  969.     mvi    c,00000000b        ; turn intensity down
  970. parn$cont:
  971.     mvi    b,00000001b        ; attribute bit to change
  972.     jr    set$FR$attr
  973.  
  974. ;
  975. ;    Set Attribute sequence
  976. ;
  977. esc$G:
  978.     call    cont$later
  979. ;
  980. ;    ESC G char
  981. ;
  982.     call    remove$exec$adr
  983.     sui    '4'            ; '4' reverse video on
  984.     jrz    esc$G$4
  985.     inr    a            ; '3' underline attr on
  986.     jrz    esc$G$3
  987.     inr    a            ; '2' blink attr on
  988.     jrz    esc$G$2
  989.     inr    a            ; '1' alt char set
  990.     jrz    esc$G$1
  991.     inr    a            ; '0' clear attributes
  992.     rnz
  993. ;
  994. ;    Rev. Video, blink, atl char set, and underline  off
  995. ;
  996. esc$G$0:
  997.     mvi    c,10000000b        ; turn attributes off
  998.     mvi    b,11110000b        ; attribute bit to change
  999.     jr    set$FR$attr
  1000.  
  1001. ;
  1002. ;    Select alt character set
  1003. ;
  1004. esc$G$1:
  1005.     mvi    c,00000000b        ; select alt character set
  1006.     mvi    b,10000000b
  1007.     jr    set$FR$attr
  1008.  
  1009. ;
  1010. ;    Blinking On
  1011. ;
  1012. esc$G$2:    
  1013.     mvi    c,00010000b        ; turn on blink attr
  1014.     jr    set$FR$atr$c
  1015.  
  1016. ;
  1017. ;    Under line
  1018. ;
  1019. esc$G$3:
  1020.     mvi    c,00100000b        ; turn on underline bit
  1021.     jr    set$FR$atr$c
  1022.  
  1023. ;
  1024. ;    Reverse Video On
  1025. ;
  1026. esc$G$4:
  1027.     mvi    c,01000000b        ; turn attributes on
  1028.  
  1029. set$FR$atr$c:
  1030.     mov    b,c            ; reverse attr
  1031. set$FR$attr:
  1032.     TJMP    FR$attr
  1033.  
  1034.